import QtQuick 1.0

Rectangle {
    id: root
    width: 320
    height: 200
    opacity: 1
    color: "transparent"

    property int activeBorisIndex: 0

    /*
    SearchBox {
        id: search;
        width: root.width
    }
    */

    VisualItemModel {
        id: mainItemModel

        BorisList {
            id: landmarks
            width: mainView.width; height: mainView.height
        }

        BorisListView {
            id: borisListView
            width: mainView.width; height: mainView.height
            onBorisIndexChanged: {
                console.log("main, boris index changed: " + borisIndex);
                //root.activeBorisIndex = borisIndex;
                mapviewer.update(borisIndex);
            }
            focus:  true
        }

        BorisDetailView {
            id: borisDetailView
            width: mainView.width; height: mainView.height
        }

        MapViewer {
            id: mapviewer
            width: mainView.width; height: mainView.height
        }
    }

    ListView {
        id: mainView
        width:  root.width; height: root.height - positionIndicator.height - 1
        anchors { top: parent.top }
        orientation: ListView.Horizontal
        snapMode: ListView.SnapOneItem;
        flickDeceleration: 400
        clip: true
        opacity: parent.opacity
        //keyNavigationWraps : true
        model: mainItemModel

        Keys.priority: Keys.BeforeItem
        focus: true

        onCurrentIndexChanged : {
            console.log("main index changed: " + currentIndex)// + "; main focus: " + currentItem.activeFocus)
        }
    }

    SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }

    Rectangle {        
        id: positionIndicator
        width: parent.width; height: 5
        anchors { bottom: parent.bottom }
        color: sysPalette.base // "transparent" //Qt.rgba(0, 39/255, 91/255, 1)
        opacity: 1
        radius: 2

        Row {
            anchors.centerIn: parent
            anchors.verticalCenter: parent.verticalCenter
            spacing: 0

            Repeater {
                model: mainItemModel.count

                Rectangle {
                    width: positionIndicator.width/mainItemModel.count; height: positionIndicator.height
                    radius: positionIndicator.radius
                    color: mainView.currentIndex == index ? sysPalette.dark : positionIndicator.color; // Qt.rgba(0, 158/255, 224/255, 1) : positionIndicator.color;
                }
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    /*
    states: [
        State {
            name: "BrowseState"
            //PropertyChanges { target: search; focus: false;  }
            PropertyChanges { target: mainView; focus: true; opacity: 1; visible: true }
        },
        State {
            name: "SearchState"
            when: Keys.onCallPressed === true
            PropertyChanges { target: mainView; focus: false; opacity: 0; visible: false }
            //PropertyChanges { target: search; focus: true;  }

        }
    ]
    */

    Component.onCompleted: {
        // mainView.currentIndex = 1;
        console.log("main loaded.");
        //borisListView.forceActiveFocus
    }

    Keys.onPressed: {
        console.log("Main key pressed: " + event.key)
        //root.state = (root.state == "SearchState") ? "BrowseState" : "SearchState"
    }

}
